import React from 'react'
// ===================================================================== Temp
import FormModal from '#cpt/temp/FormModal'
// ===================================================================== global declare
const { $fn, $http } = window
// ===================================================================== data
const statusData = [
	{ name:'停用', 		value: '-1' },
	{ name:'待校准', 	value: '0' },
	{ name:'合格', 		value: '1' },
]
// ===================================================================== component
class Index extends React.Component{
	state = {
		// 提交表单列表
		formData : [
			{ label: '设备名称',			name: 'device_id',		half:true, type: 'select', required:true, onValue:({ rows }) =>{
				this.submit.device_name = rows?.device_name
			} },
			{ label: '执行人',			name: 'ex_user', 		half:true, required:true, 	 },
			{ label: '状态',			name: 'status',			half:true, type: 'select', required:true, data: statusData },
			{ label: '实际校准时间',		name: 'operator_at', 	half:true, disabled:true, 	},
			{ label: '描述',        	name:'result', 			full:true, required:true, type:'textarea' },
		]
	}
	
	model = {}
	submit = {}
	
	open = ({uuid, device_name}, deviceData)=> {
		
		this.modal.open({ formRef:this.formRef })
		
		this.submit = { uuid }
		this.initSubmit = { device_name }
		
		const { formData } = this.state
		if(!$fn.hasArray(formData[0].data)){
			$fn.setRow(formData, 'device_id', deviceData)
			this.setState({ formData })
		}
		
		$http.submit(this,'device-plan/info',{ param:{ uuid } }).then(data=>{
			this.formRef.setValue({...data, operator_at: data.update_at})
			// 获取 device_name
			// const { device_id } = data
			// const arr = deviceData.filter(v => v.value === device_id )
			// if($fn.hasArray(arr)){ this.initSubmit = { device_name: arr[0]['device_name']  }}
		})
	}
	
	render(){
		return FormModal.call(this,{ title:'校准', labelWidth:'s7', width:700, api:'device-plan/cali'})
	}
}

export default Index